! compile with, e.g. gfortran lapackdet.f90 -llapack
program lapackdet

  implicit none
  integer :: N
  complex(kind=8), allocatable, dimension(:,:) :: mat
  complex(kind=8) :: det
  integer :: i, info
  integer, allocatable :: ipiv(:)
  real(kind=8) :: sgn

  N=2

  allocate(ipiv(N))
  allocate(mat(N,N))

  mat(1,1)=2
  mat(1,2)=1
  mat(2,1)=1
  mat(2,2)=1

  write(*,*)' initial mat:'
  write(*,*) mat

  ipiv=0

  call zgetrf(N, N, mat, N, ipiv, info)

  write(*,*)' after zgetrf  mat:'
  write(*,*) mat
 
!  det=(1.,0.)
  det=1
  do i=1, N
     det = det*mat(i,i)
  end do

  sgn=1
  do i=1, N
     if(ipiv(i)/=i)then
        sgn=-sgn
     end if
  end do
  det=sgn*det

  write(*,*)' det=', det

end program lapackdet
